package com.jyy.prefabricated.service.impl;

import com.jyy.prefabricated.dto.BatchDto;
import com.jyy.prefabricated.entity.StudentService;
import com.jyy.prefabricated.enums.BaseStatusEnum;
import com.jyy.prefabricated.enums.DeletedEnum;
import com.jyy.prefabricated.mapper.StudentServiceMapper;
import com.jyy.prefabricated.service.StudentServiceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学员服务表(StudentService)表服务实现类
 *
 * @author makejava
 * @since 2021-05-13 14:42:55
 */
@Service("studentServiceService")
public class StudentServiceServiceImpl implements StudentServiceService {
    @Resource
    private StudentServiceMapper studentServiceMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StudentService queryById(Integer id) {
        return this.studentServiceMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<StudentService> queryAllByLimit(int offset, int limit) {
        return this.studentServiceMapper.queryAllByLimit(offset, limit);
    }

    @Override
    public List<StudentService> queryList(String serviceName, Integer status) {
        StudentService studentService =new StudentService();
        studentService.setServiceName(serviceName);
        studentService.setStatus(status);
        studentService.setDeleted(DeletedEnum.INVALID.getValue());
        List<StudentService> result = studentServiceMapper.queryAll(studentService);
        return result;
    }

    /**
     * 新增数据
     *
     * @param studentService 实例对象
     * @return 实例对象
     */
    @Override
    public StudentService insert(StudentService studentService) {
        studentService.setStatus(BaseStatusEnum.INVALID.getValue());
        studentService.setDeleted(DeletedEnum.INVALID.getValue());
        this.studentServiceMapper.insert(studentService);
        return studentService;
    }

    /**
     * 修改数据
     *
     * @param studentService 实例对象
     * @return 实例对象
     */
    @Override
    public StudentService update(StudentService studentService) {
        this.studentServiceMapper.update(studentService);
        return this.queryById(studentService.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.studentServiceMapper.deleteById(id) > 0;
    }

    @Override
    public int batchUpdateStatus(BatchDto dto) {
        return studentServiceMapper.batchUpdateStatus(dto);
    }

    @Override
    public int batchUpdateDeleted(BatchDto dto) {
        return studentServiceMapper.batchUpdateDeleted(dto);
    }
}
